<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>菜品管理</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  {include file="public/css"/}
	<style>
	#ggnamediv .layui-input,#ggvaldiv .layui-input{ display:inline;height:30px}
	#ggvaldiv .thumb_img {margin-right: 5px;}
	</style>
</head>
<body>
  <div class="layui-fluid">
    <div class="layui-row layui-col-space15">
      <div class="layui-card layui-col-md12">
				<div class="layui-card-header">
					{if !$info['id']}<i class="fa fa-plus"></i> 添加菜品{else}<i class="fa fa-pencil"></i> 编辑菜品{/if}
					<i class="layui-icon layui-icon-close" style="font-size:18px;font-weight:bold;cursor:pointer" onclick="closeself()"></i>
				</div>
				<div class="layui-card-body" pad15>
					<div class="layui-form">
						<div class="layui-tab" lay-filter="mytab">
							<ul class="layui-tab-title">
								<li class="layui-this" lay-id="1">菜品信息</li>
							</ul>
							<div class="layui-tab-content">
								<div class="layui-tab-item layui-show">
									<input type="hidden" name="id" value="{$info['id']}"/>
									{if input('param.bid')}<input type="hidden" name="info[bid]" value="{$Request.param.bid}"/>{/if}
									<div class="layui-form-item">
										<label class="layui-form-label">菜品名称：</label>
										<div class="layui-input-inline" style="width:400px">
											<input type="text" name="info[name]" lay-verify="required" readonly disabled lay-verType="tips" class="layui-input" value="{$info['name']}">
										</div>
									</div>
									<div class="layui-form-item">
										<label class="layui-form-label">菜品主图：</label>
										<input type="hidden" name="info[pic]" id="pic" lay-verType="tips" class="layui-input" value="{$info['pic']}">

										<div class="layui-form-mid layui-word-aux" style="margin-left:10px;">建议尺寸：640×640像素</div>
										<div id="picPreview" class="picsList-class-110">
											<div class="layui-imgbox" style="width:100px;"><div class="layui-imgbox-img"><img src="{$info['pic']}"/></div></div>
										</div> 
									</div>
									<div class="layui-form-item">
										<label class="layui-form-label">菜品图片：</label>
										<input type="hidden" name="info[pics]" value="{$info['pics']}" id="pics">
										<div class="layui-form-mid layui-word-aux" style="margin-left:10px;">建议尺寸：640×640像素</div>
										<div id="picList" class="picsList-class-110">
											{if $info['pics']}{php}$pics = explode(',',$info['pics']);{/php}{foreach $pics as $pic}
											<div class="layui-imgbox">
												<a class="layui-imgbox-close" href="javascript:void(0)" onclick="$(this).parent().remove();getpicsval('pics','picList')" title="删除"><i class="layui-icon layui-icon-close-fill-opaque"></i></a>
												<span class="layui-imgbox-img"><img src="{$pic}"></span>
											</div>
											{/foreach}{/if}
										</div>
									</div>
									<!-- <div class="layui-form-item" >
										<label class="layui-form-label">菜品卖点：</label>
										<div class="layui-input-inline" style="width:400px">
											<input type="text" name="info[sellpoint]" class="layui-input" value="{$info['sellpoint']}">
										</div>
										<div class="layui-form-mid layui-word-aux">在菜品详情页标题下面展示卖点信息，建议60字以内</div>
									</div>
									<div class="layui-form-item">
										<label class="layui-form-label">菜品编码：</label>
										<div class="layui-input-inline">
											<input type="text" name="info[procode]" class="layui-input" value="{$info['procode']}">
										</div>
									</div> -->
									<div class="layui-form-item">
										<label class="layui-form-label">菜品分类：</label>
										<div class="layui-input-inline" style="width:300px">
											<select name="info[cid]" id="cid" xm-select="selectCid" xm-select-max="5" xm-select-search >
												<option value="">--请选择--</option>
											{foreach $clist as $cv}
												<option value="{$cv['id']}" {if in_array($cv['id'],$info['cid'])}selected{/if}>{$cv['name']}</option>
												{foreach $cv['child'] as $k=>$v}
												{if $k < count($cv['child'])-1}
												<option value="{$v['id']}" {if in_array($v['id'],$info['cid'])}selected{/if}>&nbsp;&nbsp;&nbsp;&nbsp;├ {$v['name']}</option>
												{else}
												<option value="{$v['id']}" {if in_array($v['id'],$info['cid'])}selected{/if}>&nbsp;&nbsp;&nbsp;&nbsp;└ {$v['name']}</option>
												{/if}
													{foreach $v['child'] as $k2=>$v2}
													{if $k2 < count($v['child'])-1}
													<option value="{$v2['id']}" {if in_array($v2['id'],$info['cid'])}selected{/if}>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;├ {$v2['name']}</option>
													{else}
													<option value="{$v2['id']}" {if in_array($v2['id'],$info['cid'])}selected{/if}>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└ {$v2['name']}</option>
													{/if}
													{/foreach}
												{/foreach}
											{/foreach}
											</select>
										</div>
										<div class="layui-form-mid layui-word-aux">最多可选5个分类</div>
									</div>
									<div class="layui-form-item">
										<label class="layui-form-label">出餐区域：</label>
										<div class="layui-input-inline" style="width:300px">
											<select name="info[area_id]" id="area_id">
												<option value="">--请选择--</option>
												{foreach $area_list as $cv}
												<option value="{$cv['id']}" {if $cv['id'] == $info['area_id']}selected{/if}>{$cv['name']}</option>
												{/foreach}
											</select>
										</div>
										<div class="layui-form-mid layui-word-aux">绑定出餐区域，用户下单后可分区域打印小票</div>
									</div>

									<div class="layui-form-item" id="setgg">
										<label class="layui-form-label">设置规格：</label>
										<div class="layui-input-inline" style="width:auto">
<!--											<button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="lvpriceset()" id="lvpricebtn">{if $info['lvprice']==1}关闭{else}开启{/if}会员价</button>-->
											<input type="hidden" name="info[lvprice]" value="{$info['id']?$info['lvprice']:'0'}"/>
											<table id="ggvaldiv" class="layui-table" style="margin-top:20px;">
												<thead>
													<tr>
														<th>规格</th>
														<th>市场价（元）</th>
														<th>成本价（元）</th>
														{if $info['lvprice']==1}
														{foreach $levellist as $level}
														<th class="level-price">{$level.name}（元）</th>
														{/foreach}
														{else}
														<th class="sell-price">销售价（元）</th>
														{/if}
														<th>每日库存</th>
														<th>总库存</th>
														{if $bid==0}<th>赠{:t('积分')}(个)</th>{/if}
														<th>图片</th>
<!--														<th>操作</th>-->
													</tr>
												</thead>
												{php} $i=0;$ksLast = 0;{/php}
												{if $guige_list}
												{foreach $guige_list as $ks => $gg}
												<tr data-ks="{$ks}">
													<td>
														<input name="option[{$ks}][name]" type="text" value="{$gg['name']}" disabled readonly class="layui-input"/>
													</td>
													<td>
														<input name="option[{$ks}][market_price]" readonly disabled type="text" class="layui-input" style="width:70px" value="{if $gg['market_price']!=null}{$gg['market_price']}{/if}"/>

													</td>
													<td>
														<input name="option[{$ks}][cost_price]" readonly disabled type="text" class="layui-input" style="width:70px" value="{if $gg['cost_price']!=null}{$gg['cost_price']}{/if}"/>

													</td>
													{if $info['lvprice']==1}
														{foreach $levellist as $lk=>$level}
														<td class="level-price">
															<input name="option[{$ks}][sell_price_{$level.id}]" type="text"
																   style="width:70px" value="{if $gg['lvprice_data']==null || $gg['lvprice_data'][$level['id']]!=null}{$gg['lvprice_data'][$level['id']]}{/if}" class="layui-input" id="levelprice_{$i}_{$lk}"/>
															{if $i == 0}
															{if $lk==0}
															<i class="fa fa-hand-o-down" style="cursor:pointer" title="批量设置" onclick="plset('sell_price_{$level.id}')"></i>
															{else}
															<i class="fa fa-hand-o-down" style="cursor:pointer" title="批量设置" onclick="plsetlevelprice({$i},'{$lk}')"></i>
															{/if}
															{/if}
														</td>
													{/foreach}

													{else}
													<td class="sell-price">
														<input name="option[{$ks}][sell_price]" type="text" style="width:70px" value="{if $gg['sell_price']!=null}{$gg['sell_price']}{/if}" class="layui-input"/>
														{if $i == 0}
														 <i class="fa fa-hand-o-down" style="cursor:pointer" title="批量设置" onclick="plset('sell_price')"></i>
														{/if}
													</td>
													{/if}
													<td>
														<input name="option[{$ks}][stock_daily]" type="text" style="width:60px" value="{if $gg['stock_daily']!=null}{$gg['stock_daily']}{/if}" class="layui-input"/>
														{if $i == 0}
													 	<i class="fa fa-hand-o-down" style="cursor:pointer" title="批量设置" onclick="plset('stock_daily')"></i>
														{/if}
													</td>
													<td>
														<input name="option[{$ks}][stock]" type="text" style="width:60px" value="{if $gg['stock']!=null}{$gg['stock']}{/if}" class="layui-input"/>
														{if $i == 0}
														<i class="fa fa-hand-o-down" style="cursor:pointer" title="批量设置" onclick="plset('stock')"></i>
														{/if}
													</td>
													<td id="ggpic{$ks}">
														<input type="hidden" name="option[{$ks}][pic]" id="ggpicval{$ks}" value="{if $gg['pic']!=null}{$gg['pic']}{/if}"/><img class="thumb_img" src="{if $gg['pic']!=null}{$gg['pic']}{/if}" style="max-width:50px;"/>
													</td>

												</tr>
												{php} $i++; if($i == count($guige_list)) $ksLast = $ks;{/php}
												{/foreach}
												{else}
												<tr data-ks="0">
													<td>
														<input name="option[0][name]" type="text" value="默认规格" class="layui-input"/>
													</td>
													<td>
														<input name="option[0][market_price]" type="text" class="layui-input" style="width:70px" value=""/>
														{if $i == 0}
														<i class="fa fa-hand-o-down" style="cursor:pointer" title="批量设置" onclick="plset('market_price')"></i>
														{/if}
													</td>
													<td>
														<input name="option[0][cost_price]" type="text" class="layui-input" style="width:70px" value=""/>
														{if $i == 0}
														<i class="fa fa-hand-o-down" style="cursor:pointer" title="批量设置" onclick="plset('cost_price')"></i>
														{/if}
													</td>
													{if $info['lvprice']==1}
													{foreach $levellist as $lk=>$level}
													<td class="level-price">
														<input name="option[0][sell_price_{$level.id}]" type="text" style="width:70px" value="" class="layui-input" id="levelprice_0_{$lk}"/>
														{if $i == 0}
														{if $lk==0}
														<i class="fa fa-hand-o-down" style="cursor:pointer" title="批量设置" onclick="plset('sell_price_{$level.id}')"></i>
														{else}
														<i class="fa fa-hand-o-down" style="cursor:pointer" title="批量设置" onclick="plsetlevelprice({$i},'{$lk}')"></i>
														{/if}
														{/if}
													</td>
													{/foreach}

													{else}
													<td class="sell-price">
														<input name="option[0][sell_price]" type="text" style="width:70px" value="" class="layui-input"/>
														{if $i == 0}
														<i class="fa fa-hand-o-down" style="cursor:pointer" title="批量设置" onclick="plset('sell_price')"></i>
														{/if}
													</td>
													{/if}
													<td>
														<input name="option[0][stock_daily]" type="text" style="width:60px" value="1000" class="layui-input"/>
														{if $i == 0}
														<i class="fa fa-hand-o-down" style="cursor:pointer" title="批量设置" onclick="plset('stock_daily')"></i>
														{/if}
													</td>
													<td>
														<input name="option[0][stock]" type="text" style="width:60px" value="1000" class="layui-input"/>
														{if $i == 0}
														<i class="fa fa-hand-o-down" style="cursor:pointer" title="批量设置" onclick="plset('stock')"></i>
														{/if}
													</td>
													{if $bid==0}
													<td>
														<input name="option[0][givescore]" type="text" style="width:60px" value="0" class="layui-input"/>
														{if $i == 0}
														<i class="fa fa-hand-o-down" style="cursor:pointer" title="批量设置" onclick="plset('givescore')"></i>
														{/if}
													</td>
													{/if}
													<td id="ggpic">
														<input type="hidden" name="option[0][pic]" id="ggpicval" value=""/>
														<img class="thumb_img" src="" style="max-width:50px;"/>
														<button class="layui-btn layui-btn-sm layui-btn-primary" onclick="uploader(this)" upload-input="ggpicval" upload-preview="ggpic" type="button">上传</button>
													</td>

												</tr>
												{/if}
											</table>
											<div class="layui-form-mid layui-word-aux"></div>
											<input type="hidden" name="specs" value=""/>
										</div>
									</div>
									<!--
									{if $bid==0}
									<div class="layui-form-item">
										<label class="layui-form-label">{:t('积分')}抵扣：</label>
										<div class="layui-input-block" style="width:800px">
											<input type="radio" name="info[scored_set]" value="0" {if !$info['id'] || $info['scored_set']==0}checked{/if} title="按照系统设置抵扣" lay-filter="scored_set">
											<input type="radio" name="info[scored_set]" value="1" {if $info['scored_set']==1}checked{/if} title="单独设置抵扣比例" lay-filter="scored_set">
											<input type="radio" name="info[scored_set]" value="2" {if $info['scored_set']==2}checked{/if} title="单独设置抵扣金额" lay-filter="scored_set">
											<input type="radio" name="info[scored_set]" value="-1" {if $info['scored_set']==-1}checked{/if} title="不可用{:t('积分')}抵扣" lay-filter="scored_set">
										</div>
									</div>
									<div id="scored_set1" {if $info['scored_set']!=1 && $info['scored_set']!=2}style="display:none"{/if}>
										<div class="layui-form-item">
											<label class="layui-form-label"></label>
											<div class="layui-form-mid" style="margin-right:0;background:#e6e6e6;padding: 9px 9px !important">最多抵扣(<span id="scoredkmaxunit">{$info['scored_set']==1?'%':'元'}</span>) </div>
											<div class="layui-input-inline">
												<input type="text" name="info[scored_val]" value="{$info.scored_val}" class="layui-input">
											</div>
										</div>
									</div>
									{/if}
									<div class="layui-form-item">
										<label class="layui-form-label">显示销量：</label>
										<div class="layui-input-inline">
											<input type="text" name="info[sales]" value="{$info['id']?$info['sales']:'0'}" class="layui-input">
											<input type="hidden" name="info[oldsales]" value="{$info['id']?$info['sales']:'0'}" class="layui-input">
										</div>
									</div>
									<div class="layui-form-item">
										<label class="layui-form-label">起售数量：</label>
										<div class="layui-input-inline">
											<input type="number" name="info[limit_start]" value="{$info['id']?$info['limit_start']:'0'}" class="layui-input">
										</div>
										<div class="layui-form-mid layui-word-aux">多少份起卖，0表示不限购</div>
									</div>
									<div class="layui-form-item">
										<label class="layui-form-label">每单限购：</label>
										<div class="layui-input-inline">
											<input type="number" name="info[limit_per]" min="0" value="{$info['id']?$info['limit_per']:'0'}" class="layui-input">
										</div>
										<div class="layui-form-mid layui-word-aux">每单最多可购买多少份，0表示不限购</div>
									</div>
									<div class="layui-form-item">
										<label class="layui-form-label">周几可点：</label>
										<div class="layui-input-block">
											<input type="checkbox" name="info[status_week][]" value="1" title="周一" {if (in_array(1, $info['status_week']))} checked=""{/if}>
											<input type="checkbox" name="info[status_week][]" value="2" title="周二" {if (in_array(2, $info['status_week']))} checked=""{/if}>
											<input type="checkbox" name="info[status_week][]" value="3" title="周三" {if (in_array(3, $info['status_week']))} checked=""{/if}>
											<input type="checkbox" name="info[status_week][]" value="4" title="周四" {if (in_array(4, $info['status_week']))} checked=""{/if}>
											<input type="checkbox" name="info[status_week][]" value="5" title="周五" {if (in_array(5, $info['status_week']))} checked=""{/if}>
											<input type="checkbox" name="info[status_week][]" value="6" title="周六" {if (in_array(6, $info['status_week']))} checked=""{/if}>
											<input type="checkbox" name="info[status_week][]" value="7" title="周日" {if (in_array(7, $info['status_week']))} checked=""{/if}>
										</div>
										<div class="layui-form-mid layui-word-aux">每桌最多可购买多少份，0表示不限购</div>
									</div>-->
									<!-- <div class="layui-form-item">
										<label class="layui-form-label">外卖打包费：</label>
										<div class="layui-input-inline">
											<input type="text" name="info[pack_fee]" value="{$info['id']?$info['pack_fee']:'0'}" class="layui-input">
										</div>
										<div class="layui-form-mid layui-word-aux">打包费按数量计算</div>
									</div> -->
									<div class="layui-form-item">
										<label class="layui-form-label">序号：</label>
										<div class="layui-input-inline">
											<input type="text" name="info[sort]" value="{$info['id']?$info['sort']:'0'}" class="layui-input">
										</div>
										<div class="layui-form-mid layui-word-aux">用于排序,越大越靠前</div>
									</div>
<!--									<div class="layui-form-item">-->
<!--										<label class="layui-form-label">状态：</label>-->
<!--										<div class="layui-input-inline" style="width:600px">-->
<!--											<input type="radio" name="info[status]" value="1" title="已上架" {if !$info['id'] || $info['status']==1}checked{/if} lay-filter="set_status"/>-->
<!--											<input type="radio" name="info[status]" value="0" title="未上架" {if $info['id'] && $info['status']==0}checked{/if} lay-filter="set_status"/>-->
<!--											<input type="radio" name="info[status]" value="2" title="设置上架时间" {if $info['id'] && $info['status']==2}checked{/if} lay-filter="set_status"/>-->
<!--											<input type="radio" name="info[status]" value="3" title="设置上架周期" {if $info['id'] && $info['status']==3}checked{/if} lay-filter="set_status"/>-->
<!--										</div>-->
<!--									</div>-->

<!--									<div class="layui-form-item" id="set_status2" {if $info['status']!=2}style="display:none"{/if}>-->
<!--										<label class="layui-form-label">上架时间：</label>-->
<!--										<div class="layui-input-inline" style="width:150px">-->
<!--											<input type="text" name="info[start_time]" class="layui-input" value="{$info.start_time}" id="start_time" autocomplete="off">-->
<!--										</div>-->
<!--										<div class="layui-form-mid">到</div>-->
<!--										<div class="layui-input-inline" style="width:150px">-->
<!--											<input type="text" name="info[end_time]" class="layui-input" value="{$info.end_time}" id="end_time" autocomplete="off">-->
<!--										</div>-->
<!--										<div class="layui-form-mid layui-word-aux" style="clear:left;margin-left:110px"></div>-->
<!--									</div>-->
<!--									<div class="layui-form-item" id="set_status3" {if $info['status']!=3}style="display:none"{/if}>-->
<!--										<label class="layui-form-label">上架周期：</label>-->
<!--										<div class="layui-input-inline" style="width:150px">-->
<!--											<input type="text" name="info[start_hours]" class="layui-input" value="{$info.start_hours}" id="start_hours" autocomplete="off">-->
<!--										</div>-->
<!--										<div class="layui-form-mid">到</div>-->
<!--										<div class="layui-input-inline" style="width:150px">-->
<!--											<input type="text" name="info[end_hours]" class="layui-input" value="{$info.end_hours}" id="end_hours" autocomplete="off">-->
<!--										</div>-->
<!--										<div class="layui-form-mid layui-word-aux" style="clear:left;margin-left:110px">结束时间小于或等于开始时间表示跨天,如:16:00到06:00表示下午4点到次日早晨6点</div>-->
<!--									</div>-->
									
									<div class="layui-form-item">
										<div class="layui-input-block">
<!--											<button class="layui-btn layui-btn-normal" onclick="gonext(2)">下一步:编辑菜品详情</button>-->
											<button class="layui-btn layui-btn-danger" lay-submit lay-filter="formsubmit">提 交</button>
										</div>
									</div>

								</div>
								<div class="layui-tab-item">
									<!-- 详情编辑器 -->
									<!-- <div class="layui-form-item">
										<label class="layui-form-label">菜品详情</label>
										<div class="layui-input-inline" style="width:500px">
											<script id="content" name="info[detail]" type="text/plain" style="width:100%;height:500px">{$info['detail']}</script>
										</div>
									</div> -->
									<!-- 详情编辑器 -->
									{if $info['detail_text'] || $info['detail_pics']}
									<div class="layui-form-item">
										<label class="layui-form-label" style="width:110px">菜品详情(文本)：</label>
										<div class="layui-input-inline" style="width:500px">
											<textarea name="info[detail_text]" placeholder="请输入菜品详情内容" class="layui-textarea">{$info.detail_text}</textarea>
										</div>
									</div>
									<div class="layui-form-item">
										<label class="layui-form-label" style="width:110px">菜品详情(图片)：</label>
										<input type="hidden" name="info[detail_pics]" value="{$info['detail_pics']}" id="detail_pics">
										<button style="float:left;" type="button" class="layui-btn layui-btn-primary" onclick="uploader(this,true)" upload-input="detail_pics" upload-preview="detail_picsPreview" >批量上传</button>
										<div class="layui-form-mid layui-word-aux" style="margin-left:10px;"></div>
										<div id="detail_picsPreview" style="float:left;padding-top:10px;padding-left:140px;clear: both;">
											{if $info['detail_pics']}{php}$pics = explode(',',$info['detail_pics']);{/php}{foreach $pics as $pic}
											<div class="layui-imgbox">
												<a class="layui-imgbox-close" href="javascript:void(0)" onclick="$(this).parent().remove();getpicsval('detail_pics','detail_picsPreview')" title="删除"><i class="layui-icon layui-icon-close-fill-opaque"></i></a>
												<span class="layui-imgbox-img"><img src="{$pic}"></span>
											</div>
											{/foreach}{/if}
										</div>
									</div>
									{/if}
									<?php
									$pagetitle='菜品详情';
									$pagedata= $info['detail'] && json_decode($info['detail']) ? $info['detail'] : '[{"id":"M0000000000000","temp":"richtext","params":{bgcolor:"#FFFFFF",margin_x:"0",margin_y:"0",padding_x:"10",padding_y:"10","quanxian":{"all":true},"platform":{"all":true}},"data":"","other":"","content":""}]';
									?>
									{include file="designer_page/designer_editor" /}

									<div class="layui-form-item">
										<div class="layui-input-block">
<!--											<button class="layui-btn layui-btn-normal" onclick="gonext(1)">上一步:编辑菜品信息</button>-->
											<button class="layui-btn layui-btn-danger" lay-submit lay-filter="formsubmit">提 交</button>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
  </div>
	<video id="myvideo" style="display:none"></video>
	<script>
		var formSelects = layui.formSelects;

	$(".layui-form input#video").bind("input change propertychange",function(event){
		var videourl = $('#video').val();
		if(videourl){
			$("#myvideo").prop("src", videourl);
			$("#myvideo")[0].addEventListener("loadedmetadata", function() {
				var tol = Math.floor(this.duration); //获取总时长
				$('#video_duration').val(tol);
			});
		}else{
			$('#video_duration').val(0);
		}
	})
	//var ueditor = UE.getEditor('content');
	layui.form.on('radio(freighttypeset)', function(data){
		if(data.value == '1'){
			$('#setfreight').hide();
		}else{
			$('#setfreight').show();
		}
	})

	layui.form.on('switch(isfuwu)',function(data){
		if(data.elem.checked){
			$('#isfuwudiv').show();
		}else{
			$('#isfuwudiv').hide();
		}
	})
	layui.form.on('radio(commissionset)', function(data){
		if(data.value == '1'){
			$('#commissionset1').show();
			$('#commissionset2').hide();
			$('#commissionset3').hide();
		}else if(data.value == '2'){
			$('#commissionset1').hide();
			$('#commissionset2').show();
			$('#commissionset3').hide();
		}else if(data.value == '3'){
			$('#commissionset1').hide();
			$('#commissionset2').hide();
			$('#commissionset3').show();
		}else{
			$('#commissionset1').hide();
			$('#commissionset2').hide();
			$('#commissionset3').hide();
		}
	});
	layui.form.on('radio(scored_set)', function(data){
		if(data.value == '1'){
			$('#scored_set1').show();
			$('#scoredkmaxunit').html('%');
		}else if(data.value == '2'){
			$('#scored_set1').show();
			$('#scoredkmaxunit').html('元');
		}else{
			$('#scored_set1').hide();
		}
	})
	
	layui.laydate.render({ 
		elem: '#start_hours',
		type: 'time',
		format:'HH:mm',
		trigger: 'click'
	});
	layui.laydate.render({ 
		elem: '#end_hours',
		type: 'time',
		format:'HH:mm',
		trigger: 'click'
	});
	layui.laydate.render({ 
		elem: '#start_time',
		type: 'datetime',
		trigger: 'click'
	});
	layui.laydate.render({ 
		elem: '#end_time',
		type: 'datetime',
		trigger: 'click'
	});
	layui.form.on('radio(set_status)',function(data){
		if(data.value=="0" || data.value=="1"){
			$('#set_status2').hide();
			$('#set_status3').hide();
		}
		if(data.value=="2"){
			$('#set_status2').show();
			$('#set_status3').hide();
		}
		if(data.value=="3"){
			$('#set_status2').hide();
			$('#set_status3').show();
		}
	});
	function gonext(layid){
		$(window).scrollTop(0);
		layui.element.tabChange('mytab', layid);
	}
	layui.element.on('tab(mytab)', function(){
		try{
			changeconentxy();
		}catch(e){}
	})
	//var ueditor = UE.getEditor('editor');
	var oldgglist = {:json_encode($guige_list)};
	$(function(){
		// refreshgg();
	})
	function addggtype(){
		var gghtml = '<tr>';
		gghtml += '<td><input type="text" name="ggname" class="layui-input" value="" style="width:120px" placeholder="请输入规格分组"/></td>';
		gghtml += '<td><div><input type="text" class="layui-input" style="width:180px" value="" placeholder="请输入规格名称"> <button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="addggname(this)" style="margin-top:-3px;"><i class="fa fa-plus" style="font-size:14px!important"></i></button></div></td>';
		gghtml += '<td><button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="$(this).parent().parent().remove()">删除</button></td>';
		gghtml += '</tr>';
		$('#ggnamediv').append(gghtml);
	}

	var ksLast = {$ksLast};
	function addGuige(){
		ksLast = ksLast+1;
		var lvprice = $("input[name='info[lvprice]']").val();
		var gghtml = '<tr data-ks="'+ksLast+'">';
		gghtml += '<td><input name="option['+ksLast+'][name]" type="text" value="" class="layui-input"/></td>';
		gghtml += '<td><input name="option['+ksLast+'][market_price]" type="text" class="layui-input" style="width:70px" value=""/></td>';
		gghtml += '<td><input name="option['+ksLast+'][cost_price]" type="text" class="layui-input" style="width:70px" value=""/></td>';

		if(lvprice==1){
			{foreach $levellist as $lk=>$level}
			gghtml += '<td class="level-price"><input name="option['+ksLast+'][sell_price_{$level.id}]" type="text" style="width:70px" value="" class="layui-input" id="levelprice_'+ksLast+'_{$lk}"/></td>';
			{/foreach}
		}else{
			gghtml += '<td class="sell-price"><input name="option['+ksLast+'][sell_price]" type="text" style="width:70px" value="" class="layui-input"/></td>';
		}
		gghtml += '<td><input name="option['+ksLast+'][stock_daily]" type="text" style="width:60px" value="" class="layui-input"/></td>';
		gghtml += '<td><input name="option['+ksLast+'][stock]" type="text" style="width:60px" value="" class="layui-input"/></td>';
		{if $bid==0}
		gghtml += '<td><input name="option['+ksLast+'][givescore]" type="text" style="width:60px" value="" class="layui-input"/></td>';
		{/if}
		gghtml += '<td id="ggpic-'+ksLast+'"><input type="hidden" name="option['+ksLast+'][pic]" id="ggpicval-'+ksLast+'" value=""/><img class="thumb_img" src="" style="max-width:50px;"/>';
		gghtml += '<button class="layui-btn layui-btn-sm layui-btn-primary" onclick="uploader(this)" upload-input="ggpicval-'+ksLast+'" upload-preview="ggpic-'+ksLast+'" type="button">上传</button></td>';
		gghtml += '<td><button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="delGuige(this)">删除</button></td>';
		gghtml += '</tr>';
		$('#ggvaldiv').append(gghtml);
	}
	function delGuige(obj)
	{
		ksLast = ksLast-1;
		$(obj).parent().parent().remove()
	}
	function refreshGuige()
	{
		var lvprice = $("input[name='info[lvprice]']").val();
		var gghtml = $('#ggvaldiv').html();
		var headhtml;
		var bodyhtml;
		var ks;
		if(lvprice == 0){
			//关闭
			$(".level-price").remove();
			headhtml = '<th class="sell-price">销售价（元）</th>';
			$('#ggvaldiv').find("tr").eq(0).find('th').eq(2).after(headhtml);
			$('#ggvaldiv').find("tr").each(function(i){
				bodyhtml=null;
				ks = $(this).attr('data-ks');
				if(i > 0){
					bodyhtml += '<td class="sell-price"><input name="option['+ks+'][sell_price]" type="text" style="width:70px" value="" class="layui-input"/>';
					if(i==1){
						bodyhtml += '<i class="fa fa-hand-o-down" style="cursor:pointer" title="批量设置" onClick="plset(\'sell_price\')"></i>';
					}
					bodyhtml += '</td>';

					$('#ggvaldiv').find("tr").eq(i).find('td').eq(2).after(bodyhtml);
				}
			})
		}else{
			//开启
			$(".sell-price").remove();
			{foreach $levellist as $lk=>$level}
			headhtml += '<th class="level-price">{$level.name}（元）</th>';
			{/foreach}
			$('#ggvaldiv').find("tr").eq(0).find('th').eq(2).after(headhtml);
			$('#ggvaldiv').find("tr").each(function(i){
				if(i > 0){
					bodyhtml=null;
					{foreach $levellist as $lk=>$level}
					ks = $(this).attr('data-ks');
					bodyhtml += '<td class="level-price"><input name="option['+ks+'][sell_price_{$level.id}]" type="text" style="width:70px" value="" class="layui-input" id="levelprice_'+ks+'_{$lk}"/>';
					if(i==1){
						if({$lk} == 0)
							bodyhtml += '<i class="fa fa-hand-o-down" style="cursor:pointer" title="批量设置" onclick="plset(\'sell_price_'+{$level['id']}+'\')"></i>';
						else
						bodyhtml += '<i class="fa fa-hand-o-down" style="cursor:pointer" title="批量设置" onclick="plsetlevelprice(\''+ks+'\',\'{$lk}\')"></i>';
					}
					bodyhtml += '</td>';

					{/foreach}
					$('#ggvaldiv').find("tr").eq(i).find('td').eq(2).after(bodyhtml);
				}
			})
				// oldgglist.lvprice_data[{$level.id}]
		}
	}


		function addggname(obj){
			var ggnameobj = $(obj).parent().parent().append('<div><input class="layui-input" type="text" style="width:180px" value="" placeholder="请输入规格名称"> <button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="$(this).parent().remove()" style="margin-top:-3px;"><i class="fa fa-remove" style="font-size:14px!important"></i></button></div>');
		}
		function lvpriceset(){
			var lvprice = $("input[name='info[lvprice]']").val();
			if(lvprice == 0){
				$("input[name='info[lvprice]']").val('1');
				$('#lvpricebtn').text('关闭会员价');
			}else{
				$("input[name='info[lvprice]']").val('0');
				$('#lvpricebtn').text('开启会员价');
			}
			// refreshgg()
			refreshGuige()
		}
		var specs = [];
		function refreshgg(){
			var haskong = 0
			$('#ggnamediv').find("input").each(function(){
				if($(this).val()=='') haskong = 1
			})
			if(haskong){
				layer.msg('请填写完整');return;
			}
			var lvprice = $("input[name='info[lvprice]']").val();
			specs = [];
			var i=0;
			$('input[name=ggname]').each(function(){
				var ggval = [];
				var j=0;
				$(this).parent().next().find('input').each(function(){
					ggval.push({ 'k':j,'title':$(this).val()});
					j++
				})
				specs.push({ 'k':i,'title':$(this).val(),'items':ggval});
				i++;
			});
			console.log(specs)
			var len = specs.length;
			var newlen = 1; 
			var h = new Array(len); 
			var rowspans = new Array(len); 
			
			var html = '<thead><tr>';
			for(var i=0;i<len;i++){
				html+="<th>" + specs[i].title + "</th>";
				var itemlen = specs[i].items.length;
				if(itemlen<=0) { itemlen = 1 };
				newlen*=itemlen;
				h[i] = new Array(newlen);
				for(var j=0;j<newlen;j++){
					h[i][j] = new Array();
				}
				var l = specs[i].items.length;
				rowspans[i] = 1;
				for(j=i+1;j<len;j++){
					rowspans[i]*= specs[j].items.length;
				}
			}
			//html += '<th>规格编号</th>';
			html += '<th>市场价（元）</th>';
			html += '<th>成本价（元）</th>';
			if(lvprice==1){
				{foreach $levellist as $level}
				html += '<th>{$level.name}（元）</th>';
				{/foreach}
			}else{
				html += '<th>销售价（元）</th>';
			}
			html += '<th>每日库存</th>';
			html += '<th>总库存</th>';
			{if $bid == 0}html += '<th>赠{:t('积分')}(个)</th>';{/if}
			html += '<th>图片</th>';
			html += '</tr></thead>';
			
			for(var m=0;m<len;m++){
				var k = 0,kid = 0,n=0;
				for(var j=0;j<newlen;j++){
					var rowspan = rowspans[m]; 
					if( j % rowspan==0){
						h[m][j]={ k:specs[m].items[kid].k,title: specs[m].items[kid].title, html: "<td rowspan='" +rowspan + "'>"+ specs[m].items[kid].title+"</td>\r\n",id: specs[m].items[kid].id};
					}else{
						h[m][j]={ k:specs[m].items[kid].k,title:specs[m].items[kid].title, html: "",id: specs[m].items[kid].id};	
					}
					n++;
					if(n==rowspan){
						kid++; if(kid>specs[m].items.length-1) { kid=0; }
						n=0;
					}
				}
			}

			var hh = "";
			for(var i=0;i<newlen;i++){
				hh+="<tr>";
				var ks = [];
				var titles = [];
				for(var j=0;j<len;j++){
					hh+=h[j][i].html; 
					ks.push( h[j][i].k);
					titles.push( h[j][i].title);
				}
				ks2 =ks.join('_');
				ks =ks.join(',');
				titles =titles.join(',');
				console.log(typeof(oldgglist[ks]))
				if(typeof(oldgglist[ks])!='undefined'){
					var val = oldgglist[ks];
				}else{
					var val = { procode:'',market_price:'',cost_price:'',sell_price:'',stock_daily:'1000',stock:'1000',pic:'',lvprice_data:null};
				}

				hh += '<td>';
				hh += '	<input name="option['+ks+'][name]" type="hidden" value="'+titles+'" class="layui-input"/><input name="option['+ks+'][market_price]" type="text" class="layui-input" style="width:70px" value="'+(val.market_price==null?'':val.market_price)+'"/>';
				if(i==0){
					hh += ' <i class="fa fa-hand-o-down" style="cursor:pointer" title="批量设置" onclick="plset(\'market_price\')"></i>';
				}
				hh += '</td>';
				hh += '<td>';
				hh += '	<input name="option['+ks+'][cost_price]" type="text" class="layui-input" style="width:70px" value="'+(val.cost_price==null?'':val.cost_price)+'"/>';
				if(i==0){
					hh += ' <i class="fa fa-hand-o-down" style="cursor:pointer" title="批量设置" onclick="plset(\'cost_price\')"></i>';
				}
				hh += '</td>';
				if(lvprice==1){
					{foreach $levellist as $lk=>$level}
					hh += '<td>';
					hh += '	<input name="option['+ks+'][sell_price_{$level.id}]" type="text" style="width:70px" value="'+(val.lvprice_data==null || val.lvprice_data[{$level.id}]==null?'':val.lvprice_data[{$level.id}])+'" class="layui-input" id="levelprice_'+i+'_{$lk}"/>';
					if(i==0){
						{if $lk==0}
						hh += ' <i class="fa fa-hand-o-down" style="cursor:pointer" title="批量设置" onclick="plset(\'sell_price_{$level.id}\')"></i>';
						{else}
						hh += ' <i class="fa fa-hand-o-down" style="cursor:pointer" title="批量设置" onclick="plsetlevelprice(\''+i+'\',\'{$lk}\')"></i>';
						{/if}
					}
					hh += '</td>';
					{/foreach}
				}else{
					hh += '<td>';
					hh += '	<input name="option['+ks+'][sell_price]" type="text" style="width:70px" value="'+(val.sell_price==null?'':val.sell_price)+'" class="layui-input"/>';
					if(i==0){
						hh += ' <i class="fa fa-hand-o-down" style="cursor:pointer" title="批量设置" onclick="plset(\'sell_price\')"></i>';
					}
					hh += '</td>';
				}
				/*hh += '<td>';
				hh += ' <input name="option['+ks+'][weight]" type="text" style="width:60px" value="'+(val.weight==null?'':val.weight)+'" class="layui-input"/>';
				if(i==0){
					hh += ' <i class="fa fa-hand-o-down" style="cursor:pointer" title="批量设置" onclick="plset(\'weight\')"></i>';
				}
				hh += '</td>';*/
				hh += '<td>';
				hh += ' <input name="option['+ks+'][stock_daily]" type="text" style="width:60px" value="'+(val.stock_daily==null?'':val.stock_daily)+'" class="layui-input"/>';
				if(i==0){
					hh += ' <i class="fa fa-hand-o-down" style="cursor:pointer" title="批量设置" onclick="plset(\'stock_daily\')"></i>';
				}
				hh += '</td>';
				hh += '<td>';
				hh += ' <input name="option['+ks+'][stock]" type="text" style="width:60px" value="'+(val.stock==null?'':val.stock)+'" class="layui-input"/>';
				if(i==0){
					hh += ' <i class="fa fa-hand-o-down" style="cursor:pointer" title="批量设置" onclick="plset(\'stock\')"></i>';
				}
				hh += '</td>';
				{if $bid == 0}
				hh += '<td>';
				hh += ' <input name="option['+ks+'][givescore]" type="text" style="width:60px" value="'+(val.givescore==null?'':val.givescore)+'" class="layui-input"/>';
				if(i==0){
					hh += ' <i class="fa fa-hand-o-down" style="cursor:pointer" title="批量设置" onclick="plset(\'givescore\')"></i>';
				}
				hh += '</td>';
				{/if}
				hh += '<td id="ggpic'+ks2+'"><input type="hidden" name="option['+ks+'][pic]" id="ggpicval'+ks2+'" value="'+(val.pic==null?'':val.pic)+'"/><img class="thumb_img" src="'+(val.pic==null?'':val.pic)+'" style="max-width:50px;"/> <button class="layui-btn layui-btn-sm layui-btn-primary" onclick="uploader(this)" upload-input="ggpicval'+ks2+'" upload-preview="ggpic'+ks2+'" type="button">上传</button></td>';
				hh += "</tr>";
			}
			html+=hh;
			$("#ggvaldiv").html(html);
		}
		function plset(name){
			if(name =='procode'){
				var procode = $("input[name$='["+name+"]']").eq(0).val();
				if(procode == '') procode = randomString(6);
				$("input[name$='["+name+"]']").each(function(i,v){
					if(i>0) $(this).val(procode+ '-'+i);
				})
			}else{
				$("input[name$='["+name+"]']").val($("input[name$='["+name+"]']").eq(0).val());
			}
		}
		function plsetlevelprice(i,k){
			var thisprice = $('#levelprice_'+i+'_'+k).val();
			console.log(thisprice)
			var level0price = $('#levelprice_0_0').val();
			console.log(level0price)
			if( typeof level0price == 'undefined')
			level0price = $("td.level-price").eq(0).find('input').val();
			console.log(level0price)
			// var pricepercent = thisprice / thisprice;
			// else
			var pricepercent = thisprice / level0price;
			console.log(pricepercent)
			$("input[name$='][market_price]']").each(function(i2,v2){
				var i2 = $(this).parents('tr').attr('data-ks');
				// console.log('i2='+i2);
				var this_price = ($('#levelprice_'+i2+'_0').val() * pricepercent).toFixed(2);
				console.log(this_price)
				this_price = parseInt(this_price*100)/100;
				$('#levelprice_'+i2+'_'+k).val(this_price);
			})
		}
		function randomString(len) {
		　　len = len || 32;
		　　var $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';    /****默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/
		　　var maxPos = $chars.length;
		　　var pwd = '';
		　　for (i = 0; i < len; i++) {
		　　　　pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
		　　}
		　　return pwd;
		}
	
		layui.form.on('checkbox(gettjset)', function(data){
			console.log(data)
			if(data.elem.checked){
				$('#gettjset').hide();
			}else{
				$('#gettjset').show();
			}
		})
		function chooseUrl(){
			layer.open({type:2,shadeClose:true,area:['1100px', '650px'],'title':'选择链接',content:"{:url('DesignerPage/chooseurl')}"})
		}
		function chooseLink(urlname,url){
			{if !in_array('wx',$platform)}
			hrefurl = hrefurl.replace('/d/pages/','/pages/');
			var url = hrefurl.replace('?','/').replace('&','/').replace('=','/')
			url = url.replace('/pages/','{$Think.const.PRE_URL2}/m.php?s=/') + '/aid/{$aid}';
			if(hrefurl == '/am/pages/index/index'){
				url = '{$Think.const.PRE_URL2}/am.php?s=/index/index/aid/{$aid}';
			}
			if(hrefurl == '/b/pages/index'){
				url = '{$Think.const.PRE_URL2}/m.php?s=/businessht/index/aid/{$aid}';
			}
			{/if}
			$("input[name='info[gettjurl]']").val(url);
		}
		</script>

	<script>
	layui.form.on('submit(formsubmit)', function(obj){
		var field = obj.field
		// field.specs = JSON.stringify(specs)
		//field['info[detail]'] = ueditor.getContent();
		// field['info[detail]'] = geteditordata();
		//console.log(field);return;
		// if(field['info[freighttype]'] == 0 && field['info[freightdata]'] == ''){
		// 	dialog('请选择运费模板');
		// 	return;
		// }
		var index = layer.load();
		$.post("{:url('saveCommon')}",field,function(data){
			layer.close(index);
			dialog(data.msg,data.status);
			if(data.status == 1){
				setTimeout(function(){
					parent.layer.closeAll();
					parent.tableIns.reload()
				},1000)
			}
		})
	})
  </script>
	{include file="public/copyright"/}
</body>
</html>